Page({
  data: {
    salaryData: null
  },

  onLoad(options) {
    this.fetchSalaryData();
  },

  fetchSalaryData() {
    const userId = 2; // 假设用户ID存储在全局数据中
    if (!userId) {
      wx.showToast({
        title: '请先登录',
        icon: 'none'
      });
      return;
    }

    wx.request({
      url: `http://localhost:8080/wx/salarySlip/2`,
      method: 'GET',
      header: {
        'Authorization':wx.getStorageSync('token')
      },
      success: (res) => {
        if (res.data && res.data.code === 200) {
          this.setData({
            salaryData: res.data.data
          });
        } else {
          wx.showToast({
            title: '获取薪资信息失败',
            icon: 'none'
          });
        }
      },
      fail: () => {
        wx.showToast({
          title: '网络错误',
          icon: 'none'
        });
      }
    });
  }
}); 